import re
result=re.match('ming','ming.com')
if result:
    print(result.group())
print("-"*100)
ret=re.match(".",'m')
print(ret.group())
ret=re.match('t.p','top')
print(ret.group())
ret=re.match("[hH]",'hello python')
print(ret.group())
ret=re.match('[hH]ello python','hello python')
print(ret.group())
k=re.match("嫦娥\\d号发射","嫦娥4号发射")
print(k.group())
#*匹配任意个字符是指*前面的人任意个字符
ret=re.match("[A-Z][a-z]*",'MnnM')
print(ret.group())
names=['name1','_name',"2_name",'__name__']
for name in names:
    ret=re.match("[a-zA-Z_]\\w*",name)
    if ret:
        print(f'{ret.group()}是合法变量名')
    else:
        print(f'{name}不是合法变量名')
ret=re.match("[a-zA-Z0-9_]{6}","12a3g45678")
print(ret.group())
ret=re.match("[a-zA-Z0-9]{8,20}",'13dfkj3jk3394ji')
print(ret.group())
#匹配1-99
ret=re.match(r"[1-9]?\d$|100",'100')
if ret:
    print(ret.group())
else:
    print("匹配不成功")
print("*"*100)
3.#([^-]+)代表没有遇到小横杠-就一直进行匹配，一直匹配下去
ret=re.match(r'([^-]*)-(\d*)','010-1234456')
if ret:
    print(ret.group(0))
    print(ret.group(1))
    print(ret.group(2))
    print(ret.group())
print("-"*100)
#\1代表匹配第一个分组
ret=re.match(r"<([a-zA-Z]*)>\w*</\1>","<html>hh</html>")
print(ret.group())
print(ret.group(1))
print("*"*100)
for i in range(10):
    print(i,end=' ')

print("-"*100)
def func(n):
    i=0
    while i<n:
        yield i#让进程暂停到这个位置并导出
        i+=1

for j in func(10):
    print(j,end=' ')
print('\n')
myiter=func(10)
print(next(myiter))

print("-"*100)
ret=re.sub('\\d+','998','阅读量997')
print(ret)
def add(match_result):
    '''
    返回值一定要是字符串
    :param match_reslt: 是匹配后的字符串
    :return:
    '''
    return str(int(match_result.group())+1)
ret=re.sub("\\d+",add,'书籍为666')
print(ret)
test_str="""
<div>
    <p>岗位职责<p>
<p>完成推荐算法，数据统计，接口，后台等服务器端相关工作</p>
<p><br></p>

"""
# ret=re.sub(r"<[^>]*>|&nbsp;|\n",'',test_str)
#替换标签空格和换行
ret=re.sub('<[^>]*>|&nbsp|\n','',test_str)
print(ret)
ret=re.split(r":| ",'info:xiaozhang 33 shandong')
print(ret)
s='this is a number 234-456-789'
#这里加了一个?就是将前面贪婪转化为非贪婪
r=re.match(r"(.+?)(\d+-\d+-\d+)",s)
print(r.group(2))
print(r.group(1))